package com.frame.platform.post;

import com.frame.database.PageResult;
import com.frame.pageform.DataPageForm;
import com.frame.pageform.component.JsonObject;
import com.frame.util.Pagination;

/**
 * @Title: 系统
 * @Description:
 * @Copyright: Copyright (c) 2013
 * @Company:
 * @author 王海锋
 * @CreatedTime:2013-4-11 下午09:51:36
 * @version 1.0
 */

public class PostPage extends DataPageForm{

    static{
        setForward("/platform/post/postList.jsp");
        setForward("show","/platform/post/post.jsp");
        setForward("sort","/platform/post/sort.jsp");
    }
    private String name;
    private Integer id;
    private PostBean bean;
    private String[] postIds;

    @Override
    public String execute() throws Exception {
        // TODO Auto-generated method stub
        PageResult pr=new PostDao().query(getName(), getPageSize_(), getPageNum());
        setResultList_(pr.getList());
        Pagination pageing=new Pagination(pr.getPageSize(),pr.getPageNo(),pr.getPageCount(),getResultList_().size(),pr.getResultCount());
        setPagination(pageing);
        return forward();
    }
    @Override
    public String show() throws Exception {
        // TODO Auto-generated method stub
        if(!isNew_()){
            bean=new PostDao().getPost(getId());
        }
        return forward("show");
    }
    public String sortShow() throws Exception {
        // TODO Auto-generated method stub
        setResultList_(new PostDao().getList());
        return forward("sort");
    }
    public String sort() throws Exception {
        // TODO Auto-generated method stub
        JsonObject json=getJsonObject();
        new PostDao().sortPost(getPostIds());
        json.put("state", "ok");
        return json.toString();
    }

    @Override
    public String toDel() throws Exception {
        // TODO Auto-generated method stub
        new PostDao().delPost(getPrimaryKey_());
        return execute();
    }

    @Override
    public boolean toUpdate() throws Exception {
        // TODO Auto-generated method stub
        if(new PostDao().checkName(getBean().getName(), getBean().getId())){
            if(isNew_()){
                new PostDao().addPost(getBean());
            }else
                new PostDao().updatePost(getBean());
            return true;
        }else
            throw new Exception("该岗位已经存在了！");
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public PostBean getBean() {
        return bean;
    }
    public void setBean(PostBean bean) {
        this.bean = bean;
    }
    public String[] getPostIds() {
        return postIds;
    }
    public void setPostIds(String[] postIds) {
        this.postIds = postIds;
    }

}
